package com.asa.chart;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import com.asa.chart.work.AlgoVisualizer;
import com.asa.fushu.MathUtilsFuShu;
import com.asa.fushu.RFunction;
import com.asa.fushu.bean.Fushu;

/**
 * 
 * 画复变函数
 * 
 * 改成虚数的也不是很难，难的是计算
 * 
 * @author asa
 *
 */
public class FuShuMain {
	
	public static void main(String[] args) throws Exception {
		
		//长宽随便设置了
//		test0();
		
		List<RFunction> listRF = new ArrayList<RFunction>();
		int arangestart = -50;
		int arange = 50;
//		for (int a = arangestart; a < arange; a++) {
			final int aa = 0;
			for (int b = arangestart; b < arange; b++) {
				final int bb = b;
				for (int c = arangestart; c < arange; c++) {
					final int cc = c;
					RFunction function = new RFunction() {

						@Override
						public Fushu hanshu(Fushu... a) {
							// TODO Auto-generated method stub
							if (a.length==1) {
								Fushu fushu = a[0];
								
								//x^3 
								Fushu mul = fushu.mul(fushu);
								mul = mul.mul(fushu);


								//c*x^2
								Fushu mul2 = fushu.mul(new Fushu(cc,0));
								mul2 = mul2.mul(fushu);
								mul2 = mul2.mul(fushu);



								//b*x
								Fushu mul3 = fushu.mul(new Fushu(bb,00));

								


								
								//a
								Fushu add = new Fushu(aa, 0);
								
								Fushu add3 = mul.add(mul2);
								
								Fushu add4 =add3.add(mul3);
								Fushu add5 = add4.add(add);

								
								return add5;
							}
							
							return null;
						}
						
						
					};
					listRF.add(function);
				}
				
				
				
			}
			
//		}
		
//		RFunction function = new RFunction() {
//
//			@Override
//			public Fushu hanshu(Fushu... a) {
//				// TODO Auto-generated method stub
//				if (a.length==1) {
//					Fushu fushu = a[0];
//					
//					//a^2 +a+1
//					Fushu mul = fushu.mul(fushu);
//					Fushu mul2 = fushu.mul(new Fushu(1,0));
//					Fushu add = mul.add(mul2);
//					Fushu add2 = add.add(new Fushu(-2, 0));
//
//					
////					Fushu add = sub.add(new Fushu(1,0));
////					Fushu sub = add.sub(new Fushu(1,0));
//					return add2;
//				}
//				
//				return null;
//			}
//			
//			
//		};
		
		
		
		
		//做点什么吧
		final int sceneWidth = 900;
		final int sceneHeight = 900;
		List<List<double[][]>> zhiList = new ArrayList<List<double[][]>>();//函数的线簇

		int N = 10;
		
		
		//找一元n次方程在某个范围的解，在复数域上
		
		//最笨的方法，按精度去匹对
		//
		double buchang= 0.05;
		double jindu= 0.0001;

		
		
		int asa = 5;
		
		List<Fushu> fs = new ArrayList<>();
		
//		List<String> textzhi = new ArrayList<String>();
//		List<double[]> textpointzhi = new ArrayList<double[]>();
//		for (int i = -asa; i <= asa; i++) {
//			
//			for (int j = -asa; j <= asa; j++) {
//				
//				
//				
//				Fushu e = new Fushu(i,j);
//				e = function.hanshu(e);
//				
//				
//				
//				textzhi.add("("+MathUtils.jindu(e.real,2)+":"+MathUtils.jindu(e.im,2)+")");
//				double[] pointzhi = new double[2];
//				pointzhi[0]=i;
//				pointzhi[1]=j;
//				
//				textpointzhi.add(pointzhi);
//			}
//			
//		}

//		List<Fushu> y = MathUtilsFuShu.getY(-asa, asa, -asa,asa, buchang, function);
		
		
		
//		for (int i = 0; i < listRF.size(); i++) {
//			RFunction rFunction = listRF.get(i);
//			List<Fushu> y = MathUtilsFuShu.get0jie(-asa, asa, -asa, asa, buchang, jindu, rFunction);
//			for (int j = 0; j < y.size(); j++) {
//				
//				
//				Fushu fushu = y.get(j);
//				System.out.println(fushu);
//				List<double[][]> drawpoint_x3 = fs2XY(fushu);
//				zhi.addAll(drawpoint_x3);
//				
//				
//			}
//			
//		}
		
//		Random random = new Random();
//		
//		for (int i = 0; i < listRF.size(); i++) {
//			RFunction rFunction = listRF.get(i);
//			
//			List<Fushu> y = MathUtilsFuShu.getY(-asa, asa, -asa, asa, buchang, rFunction);
//			List<double[][]> zhi = new ArrayList<double[][]>();//函数的线簇
//
//			for (int j = 0; j < y.size(); j++) {
//				
//				
//				Fushu fushu = y.get(j);
////				System.out.println(fushu);
//				List<double[][]> drawpoint_x3 = fs2XY(fushu);
//				zhi.addAll(drawpoint_x3);
//
//			}
//			zhiList.add(zhi);
//		}
		
		
		
		
		
		
		


//		AlgoVisualizer algoVisualizer = new AlgoVisualizer(sceneWidth, sceneHeight, N,zhi,90,textzhi,textpointzhi);
		
//		AlgoVisualizer algoVisualizer = new AlgoVisualizer(sceneWidth, sceneHeight, N,zhi,10);

//		AlgoVisualizer algoVisualizer = new AlgoVisualizer(sceneWidth, sceneHeight, N,1,zhiList);

	
		AlgoVisualizer algoVisualizer = new AlgoVisualizer(sceneWidth, sceneHeight, N,0.1,asa);
		algoVisualizer.setListRF(listRF);
		
		
	}

	public static List<double[][]> fs2XY(Fushu fushu1) {
		List<double[][]> drawpoint_x1 = MathPointUtil.drawpoint_x(fushu1.getReal(), fushu1.getIm());
		return drawpoint_x1;
	}

	private static void test0() {
		final int sceneWidth = 900;
		final int sceneHeight = 900;
		List<double[][]> zhi = new ArrayList<double[][]>();//函数的线簇
		int N = 10;
		
		Fushu fushu1 = new Fushu(1, 3);//平面上的一个点，理论上来说这个点的半径是无穷小，如果这样我们就无法显示它了
		List<double[][]> drawpoint_x1 = MathPointUtil.drawpoint_x(fushu1.getReal(), fushu1.getIm());
		zhi.addAll(drawpoint_x1);
		
		Fushu fushu2 = new Fushu(0, -1);//平面上的一个点，理论上来说这个点的半径是无穷小，如果这样我们就无法显示它了
		List<double[][]> drawpoint_x2 = fs2XY(fushu2);
		zhi.addAll(drawpoint_x2);
		
		Fushu mul = fushu1.mul(fushu1, fushu2);
		List<double[][]> drawpoint_x3 = MathPointUtil.drawpoint_x(mul.getReal(), mul.getIm());
		zhi.addAll(drawpoint_x3);
		mul.shownumber(mul);

		Fushu divide = fushu1.divide(mul, fushu2);
		divide.shownumber(divide);

		AlgoVisualizer algoVisualizer = new AlgoVisualizer(sceneWidth, sceneHeight, N,zhi,40);
	}
	
	
	
	
	

	
	
	
	
	

}
